package com.lcq.study.test.demo;

import cn.hutool.core.util.CharsetUtil;
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
import cn.hutool.crypto.symmetric.SymmetricCrypto;

import java.nio.charset.StandardCharsets;

/**
 * @ClassName AesUtils
 * @Description
 * @Author lichuanqi
 * @Date 2022/9/24 17:47
 * @Version 1.0
 **/
public class AesUtils {
    private AesUtils(){}

    public static String decrypt(String encrypt, String key){
        SymmetricCrypto aes = new SymmetricCrypto(SymmetricAlgorithm.AES, key.getBytes(StandardCharsets.UTF_8));
        return aes.decryptStr(encrypt, CharsetUtil.CHARSET_UTF_8);
    }

    public static String encrypt(String encryptStr, String key){
        SymmetricCrypto aes = new SymmetricCrypto(SymmetricAlgorithm.AES, key.getBytes(StandardCharsets.UTF_8));
        return aes.encryptHex(encryptStr);
    }
}
